home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / AppsToGo / Kibitz / Help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  3.6 KB  |  150 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        help.c
  5. ** Written by:  Eric Soldan
  6. **
  7. ** Copyright © 1991-1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __BALLOONS__
  21. #include <balloons.h>
  22. #endif
  23.  
  24. #ifndef __PROCESSES__
  25. #include <Processes.h>
  26. #endif
  27.  
  28. #ifndef __UTILITIES__
  29. #include <Utilities.h>
  30. #endif
  31.  
  32.  
  33.  
  34. /*****************************************************************************/
  35. /*****************************************************************************/
  36.  
  37. #ifdef applec
  38. #pragma segment Help
  39. #endif
  40.  
  41. /*****************************************************************************/
  42. /*****************************************************************************/
  43.  
  44.  
  45.  
  46. void    DynamicBalloonHelp(void)
  47. {
  48.     WindowPtr            window, oldPort;
  49.     ProcessSerialNumber    cpsn, fpsn;
  50.     FileRecHndl            frHndl;
  51.     Point                mouseLoc, tip;
  52.     ControlHandle        ctl;
  53.     Rect                rct;
  54.     short                part, message, pos, i;
  55.     long                ref;
  56.     HMMessageRecord        helpMessage;
  57.     Boolean                procsSame;
  58.     static short        lastMessage;
  59.     static short        position[4] = {5, 6, 2, 1};
  60.  
  61.     if (gSystemVersion < 0x0700) return;
  62.         /* The system can't support balloons. */
  63.  
  64.     if ((!HMGetBalloons()) || (!IsAppWindow(FrontWindow()))) {
  65.         lastMessage = 0;
  66.         return;
  67.     }        /* Balloons have been turned off, or it isn't our window anymore. */
  68.  
  69.     HMGetBalloonWindow(&window);
  70.     if (!window) lastMessage = 0;
  71.         /* There is no balloon currently, so there is no last message. */
  72.  
  73.     tip = mouseLoc = GetGlobalMouse();
  74.     part = FindWindow(mouseLoc, &window);
  75.     if ((window != FrontWindow()) || (part != inContent)) {
  76.         lastMessage = 0;
  77.         return;
  78.     }        /* We aren't over the content of the front window, so leave. */
  79.  
  80.     GetCurrentProcess(&cpsn);
  81.     GetFrontProcess(&fpsn);
  82.     SameProcess(&cpsn, &fpsn, &procsSame);
  83.     if (!procsSame) {
  84.         lastMessage = 0;
  85.         return;
  86.     }        /* We aren't the front process, so leave. */
  87.  
  88.     GetPort(&oldPort);
  89.     frHndl = (FileRecHndl)GetWRefCon(window);
  90.     SetPort(window);
  91.     SetOrigin((*frHndl)->doc.arrangeBoard * 4096, 0);
  92.     GlobalToLocal(&mouseLoc);
  93.  
  94.     ctl = ((WindowPeek)window)->controlList;
  95.     while (ctl) {
  96.         rct = (*ctl)->contrlRect;
  97.         if (PtInRect(mouseLoc, &rct)) break;
  98.         ctl = (*ctl)->nextControl;
  99.     }        /* Find the control that we are over. */
  100.  
  101.     message = 0;
  102.     if (ctl) {
  103.         message = ref = GetControlReference(ctl);
  104.         message *= 2;
  105.         if (ref > 9) {
  106.             if (ctl == (*frHndl)->doc.gameSlider) {
  107.                 message = 24;
  108.                 if (!(*frHndl)->doc.numGameMoves) --message;
  109.             }
  110.             else {
  111.                 for (i = 0; i < 2; ++i) if ((TEHandle)ref == (*frHndl)->doc.message[i]) break;
  112.                 if (i < 2) message = 19 + i + i;
  113.                 else message = 0;
  114.             }
  115.         }
  116.         else
  117.             if (FindControl(mouseLoc, window, &ctl)) --message;
  118.                 /* Use regular message for active controls. */
  119.     }
  120.     else {
  121.         rct = PaletteRect();
  122.         if (PtInRect(mouseLoc, &rct)) message = 25;
  123.     }
  124.  
  125.     if (message) {
  126.         if (lastMessage != message) {    /* If this balloon isn't current balloon... */
  127.             lastMessage = message;
  128.             helpMessage.hmmHelpType             = khmmStringRes;
  129.             helpMessage.u.hmmStringRes.hmmResID = rDynHelpStrings;
  130.             helpMessage.u.hmmStringRes.hmmIndex = message;
  131.             LocalToGlobalRect(&rct);
  132.             pos = (tip.v > (rct.top + rct.bottom) / 2) ? 2 : 0;
  133.             if (tip.h > (rct.left + rct.right) / 2) ++pos;
  134.             pos = position[pos];
  135.             SetOrigin(0, 0);
  136.             HMShowBalloon(&helpMessage, tip, &rct, nil, 0, pos, kHMRegularWindow);
  137.         }
  138.     }
  139.     else {
  140.         if (lastMessage) HMRemoveBalloon();
  141.         lastMessage = 0;
  142.     }
  143.  
  144.     SetOrigin(0, 0);
  145.     SetPort(oldPort);
  146. }
  147.  
  148.  
  149.  
  150.